def recursive_activity_selector(s,f,i,j):
    m=i+1
    while m<j and s[m]<f[i]:
        m+=1
    if m<j:
        ans=[m]
        ans.extend(recursive_activity_selector(s,f,m,j))
        return ans
    else:
        return []
def do_recursive_activity_selector(s,f):
    n=len(s)
    s.append(f[-1]+1)
    s.insert(0,-1)
    f.append(-1)
    f.insert(0,0)
    return recursive_activity_selector(s,f,0,n+1)

if __name__=='__main__':
    s=[1,3,0,5,3,5,6,8,8,2,12]
    f=[4,5,6,7,8,9,10,11,12,13,14]
    print 's:', s
    print 'f:', f
    print 'ans:', do_recursive_activity_selector(s,f)
